package org.ucas.faker.web.entity.patents;

import org.ucas.faker.web.fetcher.annotation.Connection;
import org.ucas.faker.web.fetcher.annotation.JoinCond;
import org.ucas.faker.web.utils.model.RawPatent;

import javax.persistence.*;

@Entity
@Table(name = "symbol")
@Connection(table = "patent_meta", conds = {
    @JoinCond(column = "patentId", target = "id")
})
public class Symbol implements Patentable {

  public static enum Category {
    IPC,
    IPC_MAIN,
    CPC,
    UPC,
    PRN,
    BRANCH,
    EFFECT;


    @Override
    public String toString() {
      return (new Integer(this.ordinal())).toString();
    }
  }

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  @Column(name = "kind", nullable = false)
  private Category kind;

  @Column(name = "patent_id", nullable = false)
  private Long patentId;

  @Column(name = "original")
  private String original;

  public Symbol(Category kind) {
    this.kind = kind;
  }

  public Symbol() {
  }

  public void of(RawPatent patent, boolean overwrite) {
    Symbol src = null;
    switch (kind) {
      case IPC:
        src = patent.next(patent.ipcs);
        break;
      case IPC_MAIN:
    	src = patent.next(patent.icm);
    	break;
      case CPC:
        src = patent.next(patent.cpcs);
        break;
      case PRN:
        src = patent.next(patent.prn);
        break;
      case BRANCH:
        src = patent.next(patent.br);
        break;
      case EFFECT:
        src = patent.next(patent.ef);
        break;
    }
    if(src == null) return;
    this.<Symbol>of(src,true);
  }

  public void to(RawPatent patent, boolean overwrite) {
    switch (kind) {
      case CPC:
        patent.cpcs.add(this);
        break;
      case IPC:
        patent.ipcs.add(this);
        break;
      case IPC_MAIN:
    	  patent.icm.add(this);
    	break;
      case PRN:
        patent.prn.add(this);
        break;
      case BRANCH:
        patent.br.add(this);
        break;
      case EFFECT:
        patent.ef.add(this);
        break;
    }
  }



  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }

  public Category getKind() {
    return kind;
  }

  public void setKind(Category kind) {
    this.kind = kind;
  }

  public Long getPatentId() {
    return patentId;
  }

  public void setPatentId(Long patentId) {
    this.patentId = patentId;
  }

  public String getOriginal() {
    return original;
  }

  public void setOriginal(String original) {
    this.original = original;
  }
}
